#include <allegro.h>
#include <time.h>
#include <math.h>
#include "general.h"

  






int collision_bonus(Personnage p, Vies v)
{
 if ((p.x > v.x+v.bonus->w -1)||(p.y > v.y+v.bonus->h -1)||(v.x > p.x + p.img_right[0]->w -1)||(v.y > p.y + p.img_right[0]->h -1)) {return 0;}
else {return 1;}  
}



int collision_obstacle(Personnage p, Obstacles o)
{
 if ((p.x > o.x+o.image->w -1)||(p.y > o.y+o.image->h -1)||(o.x > p.x + p.img_right[0]->w -1)||(o.y > p.y + p.img_right[0]->h -1)) {return 0;}
else {return 1;}  
}





void compter_score(BITMAP *Buffer,Personnage p)
{
int score=100;
textprintf_ex(Buffer, font, 300, 30, makecol(0,0,0),-1, " TEMPS: %f s", (float)clock()/CLOCKS_PER_SEC);

if(p.x > SCREEN_W-50) { 
clear_bitmap(Buffer);	
rectfill(Buffer, 150, 150, 600, 350 , makecol(0,0,255));

textprintf_ex(Buffer, font, 270, 200, makecol(0,0,0),-1, "vous avez mis %f secondes! ", (float)clock()/CLOCKS_PER_SEC);



if ((float)clock()/CLOCKS_PER_SEC<=10) 
{ 
textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); 
}
else if ((float)clock()/CLOCKS_PER_SEC<=20) 
{score=score-20;
 textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); 
}
else if ((float)clock()/CLOCKS_PER_SEC<=40) {
score=score-40;
 textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); }
else if ((float)clock()/CLOCKS_PER_SEC<=60) {
score=score-60;
 textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); }
else if ((float)clock()/CLOCKS_PER_SEC<=80) { 
score=score-80;
textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); }
else { score=score-100;
textprintf_ex(Buffer,font,270,230,makecol(0,0,0),-1,"SCORE: %d",score); }


blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}

textprintf_ex(Buffer,font,730,39.5,makecol(0,0,0),-1," 0");
}




void compter_vie(BITMAP *Buffer,Personnage p,Obstacles o,Vies v)
{

while(v.vie!=0)
{
if(p.y==600){v.vie--;}
if (  collision_obstacle(p,o)==1 ) {v.vie--;}
if (  collision_bonus(p,v)==1 ) {v.vie++;}
}

textprintf_ex(Buffer, font, 270, 170, makecol(255,0,0),-1, "vous avez perdu! ", (float)clock()/CLOCKS_PER_SEC);

compter_score(Buffer,p);

}



